import { ObservedTarget } from "./ObservedTarget";
import { Tree } from "../components/base/Tree";
import { debug } from "@tauri-apps/plugin-log";
import { IComponent } from "../components/base/IComponent";
import { DomView } from "../DomView";

export class ObservedMap {
    static componentTree: Tree<IComponent> = new Tree();
    static viewTree: Tree<DomView> = new Tree();
    private static map: Map<string, ObservedTarget<any>> = new Map();

    static register(key: string, target: ObservedTarget<any>): void {
        ObservedMap.map.set(key, target);
    }

    static query(key: string): ObservedTarget<any> | undefined {
        return ObservedMap.map.get(key);
    }

    static fireChangeV1() {
        debug("fireChangeV1");
        const root = this.componentTree.top();
        if (root) {
            root.build();
        }
    }
}